package it.koutifaris.travianmap.utils;

public class UrlStringParser {

	public String getHost(String urlString) {
		return removePathIfExist(removeProtocolIfExist(urlString));
	}

	public String removeProtocolIfExist(String urlString) {
		String result = urlString;

		int indexOfSlashes = urlString.indexOf("//");
		if (indexOfSlashes >= 0) {
			result = result.substring(indexOfSlashes + 2);
		}

		return result;
	}

	public String removePathIfExist(String urlString) {
		String result = urlString;

		int indexOfSlash = urlString.lastIndexOf("/");
		if (indexOfSlash >= 0) {
			result = result.substring(0, indexOfSlash);
		}

		return result;
	}

}
